package traveldream.ejb.sessionBean;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import traveldream.ejb.DTO.HotelDTO;
import traveldream.ejb.DTO.TransportationDTO;
import traveldream.ejb.entities.Hotel;
import traveldream.ejb.entities.TransportationMean;
import traveldream.ejb.interfaces.NotFindException;
import traveldream.ejb.interfaces.TransportEditBeanLocal;

/**
 * Session Bean implementation class TransportEditBean
 */
@Stateless
public class TransportEditBean implements TransportEditBeanLocal {

	@PersistenceContext
	private EntityManager em;
	private TransportationMean t;
    /**
     * Default constructor. 
     */
    public TransportEditBean() {
        // TODO Auto-generated constructor stub
    }
    
	@Override
	public void edit(TransportationDTO tDTO) {
		// TODO Auto-generated method stub
		t.convertFromDTO(tDTO);
		em.merge(t);
	}

	@Override
	public TransportationDTO find(int id) throws NotFindException{
		// TODO Auto-generated method stub0
		try{
		return (this.t=em.find(TransportationMean.class,id)).convertToDTO();
		}
		catch(NullPointerException e){
			throw new NotFindException();
		}
	}

}
